<?php
	
	$show = "show";
	$id = "id";
		
	if(isset($_GET[$show])) {
		if(isset($_GET[$id])) {

			# panoramio get images in geograpic offset
			echo "<center>Panoramio&copy; <br> Related Images:<br><br></center>";
			$conn = connectDB();
			
			$id = $_GET[$id];
			// query DB

			$result = queryDB("SELECT gps_latitude, gps_longitude FROM image WHERE ID=$id", $conn);
			
			$num = mysql_numrows($result);
			
			// get row of results from query
			$row = mysql_fetch_array($result, MYSQL_NUM);
			
			if($row[1] == NULL) {
				echo "N/A<br><br>";
			}
			else {
	
				$lat = $row[0];
				$lon = $row[1];
				$offset = 0.0005;
				$minx = $lon - $offset;
				$miny = $lat - $offset;
				$maxx = $lon + $offset;
				$maxy = $lat + $offset;
				
				$her = file_get_contents('http://www.panoramio.com/map/get_panoramas.php?order=upload_date&set=full&from=0&to=20&minx='.$minx.'&miny='.$miny.'&maxx='.$maxx.'&maxy='.$maxy.'&size=thumbnail');
				
				#echo $her."<br>";
				
				$object = json_decode($her);
				
				echo "<center>";
				
				$i = 0;
				foreach(($object->photos) as $value) {
					if ($i == 20) 
						break;
					$upload_date = $value->upload_date;
					$image_thumb_url = $value->photo_file_url;
					$page_url = $value->photo_url;
					$title = $value->photo_title;
					$id = $value->photo_id;
					
					$img_url = "http://mw2.google.com/mw-panoramio/photos/medium/".$id.".jpg";
					
					$new_width = 390;
					$new_height = 290;
					
					echo '<a href="'.$page_url.'" target="_blank" onmouseover="doTooltip(event,0,\''.$img_url.'\',\''.$title.'\','.$new_height.' ,'.$new_width.' )" onmouseout="hideTip()">'; 
					echo '<img src="'.$image_thumb_url.'" alt="'.$title.'"height="75" width="100" />';
					echo '</a><br><br>';

					$i = $i + 1;
				}
				
			}
			echo "<small>&copy;Panoramio</small>";
			echo "</center>";
		}
	}

?>
	
  